#include "jni_util.h"

JNIHandle::JNIHandle() = default;

JNIHandle::~JNIHandle() = default;

JNIHandle *JNIHandle::GetInstance() {
    static JNIHandle jniHandle;
    return &jniHandle;
}

void JNIHandle::Init(JNIEnv *env) {

    env->GetJavaVM(&jvm);

    /** PicTranscoder */
    jclass tmpClsPicTranscoder = env->FindClass("com/arcvideo/system/sdk/PicTranscoder");
    cls_picTranscoder = (jclass)(env->NewGlobalRef(tmpClsPicTranscoder));
    fid_picTranscoder_maxParallelNum = env->GetFieldID(tmpClsPicTranscoder, "maxParallelNum", "I");
    fid_picTranscoder_ctx = env->GetFieldID(tmpClsPicTranscoder, "ctx", "J");
    env->DeleteLocalRef(tmpClsPicTranscoder);

    /** Task */
    jclass tmpClsTask = env->FindClass("com/arcvideo/system/sdk/Task");
    cls_task = (jclass) env->NewGlobalRef(tmpClsTask);
    fid_task_inputPath = env->GetFieldID(tmpClsTask, "inputPath", "Ljava/lang/String;");
    fid_task_outPath = env->GetFieldID(tmpClsTask, "outPath", "Ljava/lang/String;");
    fid_task_thumbnailPath = env->GetFieldID(tmpClsTask, "thumbnailPath", "Ljava/lang/String;");
    fid_task_thumbnailWidth = env->GetFieldID(tmpClsTask, "thumbnailWidth", "I");
    fid_task_profile = env->GetFieldID(tmpClsTask, "profile", "I");
    fid_task_quality = env->GetFieldID(tmpClsTask, "quality", "I");
    fid_task_isSync = env->GetFieldID(tmpClsTask, "isSync", "Z");
    env->DeleteLocalRef(tmpClsTask);

}
